const connection = require('../app/database');
const authService = require("../service/auth");
const jwt = require('jsonwebtoken');
const app = require("../app");
const {private_key} = require("../app/config");

class authController {
  async login(ctx, next) {
    let {name, id} = ctx.user;
    console.log(name, id, "name, id");
    const token = jwt.sign({id, name}, private_key, {  //sign the token
      expiresIn: '10h',
      algorithm: 'RS256',
    });
    ctx.body = {
      code: 200,
      id,
      name: name,
      token: token,
      message: '登录成功'

    }
  }

  // 测试是否在登录授权后进行一操作
  async test(ctx, next) {
    let {name, id} = ctx.user;
    console.log(name, id, "name, id");
    ctx.body = 'test'; // 去掉request
  }
}

module.exports = new authController();